import {Body, Controller, Get, Headers, Post, Query, UseGuards} from '@nestjs/common';
import {ApiBearerAuth, ApiOperation, ApiTags} from "@nestjs/swagger";
import {getStatusDto} from "./dto/get-status.dto";
import {AuthGuard} from "@nestjs/passport";
import {GetUser} from "@app/common/decorations/getUser.drcorator";
import {ActionsService} from "./actions.service";
import {createBrowseDto} from "./dto/create-browse.dto";

@Controller('actions')
@ApiTags('操作')
export class ActionsController {
  constructor(private readonly actionsService: ActionsService) {
  }

  @Get('/status')
  @ApiOperation({summary: '获取状态'})
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth()
  async getStatus(@Query() query: getStatusDto, @GetUser() user) {
    return await this.actionsService.getStatus(query, user)
  }

  @Post('/toggle')
  @ApiOperation({summary: '切换状态'})
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth()
  async toggleStatus(@Body() body: getStatusDto, @GetUser() user) {
    return await this.actionsService.toggleStatus(body, user)
  }

  @Get('/lists')
  @ApiOperation({summary: '获取正确状态列表'})
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth()
  async getLists(@Query('query') query: string, @GetUser() user) {
    return await this.actionsService.getList(query, user)
  }

  @Get('/browsers')
  @ApiOperation({summary: '获取浏览量'})
  async getBrowseLists(@Query('query') query: string) {
    return await this.actionsService.getList(query)
  }

  @Post('/browsers')
  @ApiOperation({summary: '增加浏览量'})
  async createBrowse(@Body() body: createBrowseDto, @Headers('Authorization') header) {
    return await this.actionsService.createBrowse(body, header)
  }
}
